'use strict';

const Controller = require('egg').Controller;

class GisController extends Controller {
    async getLocationByTagId() {
        const {
            ctx,
            service
        } = this;
        // 从这里开始写业务逻辑
        const options = {};
        const param = ctx.request.body;
        if (param.objectCode) {
            options.objectCode = param.objectCode;
        }
        if (param.startDate && param.endDate) {
            options.startDate = param.startDate;
            options.endDate = param.endDate;
        }
        const epc = await service.admin.gis.getTagIdByObjectCode(param.objectCode);
        const contractInfo = await service.admin.alarm.queryContractId(epc);
        let lockType = contractInfo.objectType.indexOf('GPS') != -1;
        let result = await service.admin.gis.getGpsLocationByTagId(options);

        console.log(29, options)
        if (result.length) {
            ctx.response.success(result);
        } else {
            ctx.response.failByCode('1002', 200, '暂无轨迹');
        }
        const des = `【${ctx.curAdminUser.realName}】在【${ctx.getDate_YYYY_MM_DD_HH_mm_ss()}】查询了${JSON.stringify(param)}`;
        ctx.writeSysOperationLogs('查询历史轨迹', ctx.getSystemLogType('QUERY'), {
            curAdminUser: ctx.curAdminUser,
            des
        });
    }

}

module.exports = GisController;